<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Renting extends Base
{
    //追加字段
    protected $appends=['img_list'];
    //访问器
    public function getImgListAttribute(){
        $domain=$this->domain;
        $imgs=trim($this->card_img,"#");
        $imgs=explode("#",$imgs);
        return array_map(function ($item)use($domain){
            return $domain.$item;
        },$imgs);
    }
    //租客--房源  多对多
    public function fangs(){
        return $this->belongsToMany(Fang::class,'favs','rent_id','fang_id');
    }
    //租客-房源记录 多对多
    public function recs(){
        return $this->belongsToMany(Fang::class,'fang_counts','rid','fang_id');
    }
}
